
<template>
  <div class="box">
    <div class="box-left">
      <div class="box-left-card">
        <section>
          <div>较上日{{ list.chinaAdd.localConfirmH5 }}</div>
          <div>{{ list.chinaAdd.localConfirm }}</div>
          <div>本土现有确诊</div>
        </section>
        <section>
          <div>较上日{{ list.chinaAdd.nowConfirm }}</div>
          <div>{{ list.chinaAdd.nowConfirm }}</div>
          <div>现有确诊</div>
        </section>
        <section>
          <div>较上日{{ list.chinaAdd.confirm }}</div>
          <div>{{ list.chinaAdd.confirm }}</div>
          <div>累计确诊</div>
        </section>
        <section>
          <div>较上日{{ list.chinaAdd.noInfect }}</div>
          <div>{{ list.chinaAdd.noInfect }}</div>
          <div>无症状感染者</div>
        </section>
        <section>
          <div>较上日{{ list.chinaAdd.importedCase }}</div>
          <div>{{ list.chinaAdd.importedCase }}</div>
          <div>境外输入</div>
        </section>
        <section>
          <div>较上日{{ list.chinaAdd.dead }}</div>
          <div>{{ list.chinaAdd.dead }}</div>
          <div>累计死亡</div>
        </section>
      </div>
      <div class="box-left-pie"></div>
      <div class="box-left-line"></div>

    </div>
    <div class="box-center" id="china"></div>
    <div class="box-right">
      <table class="table" cellspacing="0" border="1">
        <thead>
          <tr>
            <th>地区</th>
            <th>新增确诊</th>
            <th>累计确诊</th>
            <th>治愈</th>
            <th>死亡</th>
          </tr>
        </thead>
        <TransitionGroup enter-active-class="animate__animated animate__fadeInDown" tag="tbody">
          <tr v-for="item in list.item" :key="item.name">
            <td>{{ item.name }}</td>
            <td>{{ item.today.confirm }}</td>
            <td>{{ item.total.confirm }}</td>
            <td>{{ item.total.heal }}</td>
            <td>{{ item.total.dead }}</td>
          </tr>
        </TransitionGroup>

      </table>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useCityList } from './store/getlist'
import { onMounted } from 'vue';
import * as echarts from 'echarts'
import './assets/china.js'

import { geoCoordMap } from './assets/geoMap'

import 'animate.css';

const list = useCityList()
onMounted(async () => {
  await list.getList()
  // console.log(list.list.diseaseh5Shelf.areaTree[0]);
  initCharts()
  //饼状图
  initPie()
  //折线图
  initLine()
})

const initCharts = () => {

  const city = list.list.diseaseh5Shelf.areaTree[0].children


  //右侧表格默认数据
  list.item = city[12].children
  const data = city.map(item => {
    return {
      name: item.name,
      value: geoCoordMap[item.name].concat(item.total.nowConfirm),
      children: item.children
    }
  })

  const charts = echarts.init(document.querySelector('#china') as HTMLElement)

  charts.setOption({
    geo: {
      map: "china",
      aspectScale: 0.8,
      layoutCenter: ["50%", "50%"],
      layoutSize: "100%",
      itemStyle: {
        //  normal: {
        areaColor: {
          type: "linear-gradient",
          x: 0,
          y: 1200,
          x2: 1000,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: "#152E6E", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "#0673AD", // 50% 处的颜色
            },
          ],
          global: true, // 缺省为 false
        },
        shadowColor: "#0f5d9d",
        shadowOffsetX: 0,
        shadowOffsetY: 15,
        opacity: 0.5,
        // },

      },
      emphasis: {
        areaColor: "#0f5d9d",
      },

      regions: [
        {
          name: "南海诸岛",
          itemStyle: {
            areaColor: "rgba(0, 10, 52, 1)",
            borderColor: "rgba(0, 10, 52, 1)",
            //normal: {
            opacity: 0,
            label: {
              show: false,
              color: "#009cc9",
            },
            //},
          },
          label: {
            show: false,
            color: "#FFFFFF",
            fontSize: 12,
          },
        },
      ],
    },
    series: [
      {
        type: "map",
        map: "china",
        aspectScale: 0.8,
        layoutCenter: ["50%", "50%"], //地图位置
        layoutSize: "100%",
        label: {
          show: true,
          color: "#FFFFFF",
          fontSize: 12,
        },
        itemStyle: {
          areaColor: "#0c3653",
          borderColor: "#1cccff",
          borderWidth: 1.8,
        },
        emphasis: {
          areaColor: "#56b1da",
          label: {
            show: true,
            color: "#fff",
          },
        },
        data: data,
      },
      {
        type: 'scatter',
        coordinateSystem: 'geo',
        symbol: 'pin',
        symbolSize: [45, 45],
        label: {
          show: true,
          color: "#fff",
          formatter(value: any) {
            return value.data.value[2]
          }
        },
        itemStyle: {
          color: '#1E90FF', //标志颜色
        },
        data: data,
      },
    ],
  })
  //点击生成表格
  charts.on('click', (e: any) => {
    console.log(e.data);
    list.item = e.data.children
  })
}

const initPie = () => {
  const charts = echarts.init(document.querySelector('.box-left-pie') as HTMLElement)
  charts.setOption({
    // title: {
    //   text: 'Referer of a Website',
    //   subtext: 'Fake Data',
    //   left: 'center'
    // },
    backgroundColor: '#223651',

    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '80%',
        data: list.statisGradeCityDetail.map(item => {
          return {
            name: item.city,
            value: item.nowConfirm,
          }
        }),
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)',
            // color: 'white'
          }
        }
      }
    ]
  })
}
//折线图
const initLine = () => {
  const charts = echarts.init(document.querySelector('.box-left-line') as HTMLElement)
  charts.setOption({
    backgroundColor: '#223651',
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      data: list.statisGradeCityDetail.map(item => item.city),
      axisLine: {
        lineStyle: {
          color: "#fff"
        }
      }
    },
    yAxis: {
      type: 'value',
      axisLine: {
        lineStyle: {
          color: "#fff"
        }
      }
    },
    label: {
      show: true
    },
    series: [
      {
        data: list.statisGradeCityDetail.map(item => item.nowConfirm),
        type: 'line',
        smooth: true
      }
    ]
  })
}
</script>



<style lang="less" >
* {
  padding: 0;
  margin: 0;
}

@itemColor: #41b0db;
@itemBg: #223651;
@itemBorder: #212028;

.animate__animated.animate__fadeInDown {
  --animate-duration: 1.3s;
}

.table {
  width: 100%;
  background-color: #212028;
  color: white;

  tr {
    th {
      padding: 5px;
      white-space: nowrap;
    }

    td {
      padding: 5px 10px;
      width: 100px;
      white-space: nowrap;
    }
  }
}

html,
body,
#app {
  height: 100%;
  overflow: hidden;
}

.box {
  height: 100%;
  display: flex;
  overflow: hidden;
  padding: 10px;
  background: url(../public/1.jpg);

  &-left {
    width: 400px;
    color: white;

    &-pie {
      height: 320px;
      margin-top: 20px;
    }

    &-line {
      height: 320px;
      margin-top: 20px;
    }

    &-card {
      display: grid;
      grid-template-columns: auto auto auto;
      grid-template-rows: auto auto;

      section {
        background: @itemBg;
        border: 1px solid @itemBorder;
        padding: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;

        div:nth-child(2) {
          color: @itemColor;
          padding: 10px 0;
          font-size: 20px;
          font-weight: bold;
        }
      }
    }
  }

  &-center {
    flex: 1;
  }

  &-right {
    width: 450px;
  }
}
</style>
